import {request} from "@/api";
import {DictPageDTO, SysDict} from "@/api/dict/types.ts";
import {Page} from "@/api/types.ts";

const apiPrefix = '/varian-system/dict'

export const dictApi = {
    page: (params: DictPageDTO) => request.get<Page<SysDict>>(`${apiPrefix}/page`, {params}),
    addType: (data: SysDict) => request.post(`${apiPrefix}/type`, {data}),
    addItem: (data: SysDict) => request.post(`${apiPrefix}/item`, {data}),
    modifyType: (data: SysDict) => request.put(`${apiPrefix}/type/${data.id}`, {data}),
    modifyItem: (data: SysDict) => request.put(`${apiPrefix}/item/${data.id}`, {data}),
    detail: (id: string) => request.get<SysDict>(`${apiPrefix}/${id}`),
    delete: (id: string) => request.delete(`${apiPrefix}/${id}`),
    listByDictCode: (dictCode: string) => request.get<SysDict[]>(`${apiPrefix}/list/${dictCode}`),
    mapByDictCodes: (dictCodes: string[]) => request.post<Record<string, SysDict[]>>(`${apiPrefix}/map-by-dict-code`, {data: dictCodes})
}
